package com.test.spring.transaction.xml.service.impl;

import com.test.spring.transaction.xml.BookShopDao;
import com.test.spring.transaction.xml.service.BookShopService;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2018/9/29 10:28
 */
public class BookShopServiceImpl implements BookShopService {
    private BookShopDao bookShopDao;

    public void setBookShopDao(BookShopDao bookShopDao) {
        this.bookShopDao = bookShopDao;
    }

    @Override
    public void purchase(String username, String isbn) {
        //1.获取书的单价
        double price = bookShopDao.findBookPriceByIsbn(isbn);

        //2.更新书的库存
        bookShopDao.updateBookStock(isbn);

        //3.更新用户余额
        bookShopDao.updateUserAccount(username, price);
    }
}
